
const Builder = require('./Builder');

class Model extends Builder {
    static instance = null;

    // 表名
    table = '';
    // 主键字段
    primaryKey = 'id';

    async findOne(id) {
        return await this.where(this.primaryKey, id).first();
    }

    save(data) {
        if(!`${this.primaryKey}` in data) {
            console.log('in create');
            return this.insert(data);
        }
        const updates = data;
        return this.where(this.primaryKey, data[this.primaryKey]).update(updates);
    }
}

module.exports = Model;